import { CustomViewer } from "../CustomCesium/CustomCesium";
import DomainUtils from "./DomainUtils";
import { IFireAndInfo } from "@@/typings/deduct-control";
import { FireGroupId, InfoGroupId } from "@@/enums/observation";

export default class DomainManagerTuiyan {
  /**
   * 初始化域
   * @param customViewer
   * @param step
   * @param visualAngle
   */
  async createInit(
    customViewer: CustomViewer,
    step: IFireAndInfo,
    visualAngle: string,
    fireShow: boolean,
    infoShow: boolean
  ) {
    createFireInit(customViewer, step, visualAngle, fireShow);
    createInfoInit(customViewer, step, visualAngle, infoShow);
  }

  /**
   * 更新轨迹
   * @param customViewer
   * @param step
   * @param visualAngle
   */
  updatePath(
    customViewer: CustomViewer,
    step: IFireAndInfo,
    visualAngle: string
  ) {
    const fireGroup = customViewer.animationManager?.getAnimationGroup(
      FireGroupId[visualAngle]
    );
    const infoGroup = customViewer.animationManager?.getAnimationGroup(
      InfoGroupId[visualAngle]
    );
    if (fireGroup) {
      DomainUtils.updatePath(
        customViewer,
        fireGroup,
        step,
        visualAngle,
        "fire"
      );
    }
    if (infoGroup) {
      DomainUtils.updatePath(
        customViewer,
        infoGroup,
        step,
        visualAngle,
        "info"
      );
    }
  }
}

export function createDomainManagerTuiyan() {
  return new DomainManagerTuiyan();
}
function createFireInit(customViewer: CustomViewer, step: IFireAndInfo, visualAngle: string, fireShow: boolean) {
  const fire =
    step &&
    DomainUtils.createInitDomain(customViewer, step, visualAngle, "fire");
  const fireGroup =
    fire &&
    customViewer.animationManager?.createAnimationGroup(
      FireGroupId[visualAngle],
      FireGroupId[visualAngle],
      fire.period,
      fire.animations
    );
  fireGroup &&
    (customViewer.animationManager?.renderAnimationGroup(fireGroup));
  fireGroup && (fireGroup.datasource.show = fireShow);
}

function createInfoInit(customViewer: CustomViewer, step: IFireAndInfo, visualAngle: string, infoShow: boolean) {
  const info =
    step &&
    DomainUtils.createInitDomain(customViewer, step, visualAngle, "info");

  const infoGroup =
    info &&
    customViewer.animationManager?.createAnimationGroup(
      InfoGroupId[visualAngle],
      InfoGroupId[visualAngle],
      info.period,
      info.animations
    );

  infoGroup &&
    (customViewer.animationManager?.renderAnimationGroup(infoGroup));

  infoGroup && (infoGroup.datasource.show = infoShow);
}
